#!/bin/bash

# Linux环境下的编译测试脚本
echo "开始编译无人机演示项目..."

# 进入项目目录
cd "$(dirname "$0")" || {
    echo "错误：无法进入项目目录"
    exit 1
}

# 清理并创建build目录
echo "清理并创建build目录..."
rm -rf build
mkdir -p build || {
    echo "错误：无法创建build目录"
    exit 1
}
cd build || {
    echo "错误：无法进入build目录"
    exit 1
}

# 运行cmake生成Makefile
echo "正在生成Makefile..."
cmake .. || {
    echo "错误：CMake配置失败"
    exit 1
}

# 执行make编译
echo "正在编译..."
make || {
    echo "错误：编译失败，请检查错误信息"
    exit 1
}

# 检查编译结果
if [ -f "drone_demo" ]; then
    echo "编译成功！"
    echo "可执行文件: drone_demo"
    echo "可以使用 ./drone_demo 运行程序"
else
    echo "错误：编译似乎成功但未找到可执行文件"
    exit 1
fi